# coding=utf-8
import unittest
from db_fixture.data import insertData
from HTMLTestRunner import HTMLTestRunner
from datetime import datetime

# 数据库操作
# 插入测试数据
insertData()
# 生成测试套件
# defaultTestLoader()类，通过该类下面的discover()方法可自动更具测试目录start_dir匹配查找测试用例文件（test*.py），并将查找到的测试用例组装到测试套件
all_cases = unittest.defaultTestLoader.discover(start_dir='./cases', pattern='test*.py')
# print(all_cases)
# 执行测试用例
# runner = unittest.TextTestRunner()
nowtime = datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
file_path = './report/' + nowtime + '_result.html'
with open(file_path, 'wb') as f:
    runner = HTMLTestRunner(stream=f, title='系统接口测试报告', description='用例执行情况')
    runner.run(all_cases)
